<?php

session_start();

class administrator extends CI_Controller {

    function index() {
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
            $data['konten'] = 'administrator';
            $this->load->view('home', $data);
        } else {
            //If no session, redirect to login page
            redirect('login', 'refresh');
        }
        //$data['konten'] = 'administrator';
        // $this->load->view('home', $data);
    }

    function user() {
        $this->load->model('user');
        $data['daftar_user'] = $this->user->get_user_all();
        $data['konten'] = 'sidebar';
        $this->load->view('home', $data);
    }

    function editadmin() {
        $data['judul'] = 'Update Data User';
        $this->load->model('user');
        $data['edit'] = $this->user->edit_admin(1);
        $data['konten'] = 'administrator';
        $this->load->view('home', $data);
    }

    function simpan_edit_admin() {
        $this->load->library('form_validation');

        $id = $this->input->post(1);
        //$username = $this->input->post('username');
        $password = $this->input->post('password');

        $this->form_validation->set_rules('password', 'Password', 'min_length[5]');

        $this->load->model('user');
        $data['edit'] = $this->user->simpan_edit_admin($id, /* $username, */ $password);
        $data['notifikasi'] = 'Password Telah Berubah';
        $data['konten'] = 'administrator_x';
        $this->load->view('home', $data);
    }

    function logout() {
        $this->session->unset_userdata('logged_in');
        session_destroy();
        redirect('home', 'refresh');
    }

}

?>